package com.sskj.xyft;


import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.webkit.WebView;
import android.widget.LinearLayout;

import com.just.agentweb.AgentWeb;
import com.sskj.base.Constant;
import com.sskj.base.view.ToolBarLayout;
import com.sskj.xyft.R;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/03/27
 */
public class WebViewActivity extends MVPActivity<WebViewPresenter> {

    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.webView)
    WebView webView;
    AgentWeb mAgentWeb;
    private String url = "";

    @Override
    public int getLayoutId() {
        return R.layout.activity_web_view;
    }

    @Override
    public WebViewPresenter getPresenter() {
        return new WebViewPresenter();
    }

    @Override
    public void initView() {
        toolbar.setLeftButtonOnClickListener(v -> finish());
        url = getIntent().getStringExtra("url");
        mAgentWeb = AgentWeb.with(this)
                .setAgentWebParent(webView, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .createAgentWeb()
                .ready()
                .go(url);
//        if (TextUtils.isEmpty(url)) {
//            return;
//        }
//        String CSS_STYLE = "<style>* {font-size:40px;line-height:60px;} p {color:#fff;} a {color:#fff;} img {width:100%;} pre {font-size:40pt;line-height:60pt;font-family:Courier New,Arial;border:1px solid #ddd;border-left:5px solid #fff;background:#fff;padding:5px;}</style>";
//        url = url.replaceAll("<span.*?</span><span.*?</span>", "").replace("“", "").replace("”", "");
//        url = "<body style=\"background:#2D3033;margin:0;padding-left:15px;padding-right:15px;margin-top:20px\">" + url + "</body" +
//                ">";
//        mAgentWeb.getUrlLoader().loadDataWithBaseURL(Constant.SERVER_ADDRESS, url, "text/html; charset=UTF-8", null, Constant.SERVER_ADDRESS);
    }

    @Override
    public void initData() {

    }

    public static void start(Context context, String url) {
        Intent intent = new Intent(context, WebViewActivity.class);
        intent.putExtra("url", url);
        context.startActivity(intent);
    }

}
